package org.sundatagroup.aurora.core.config;

import java.util.concurrent.Executor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 异步消息的配置类
 * @author Zdream
 * @date 2018-05-30
 * @since 0.2.0
 */
@Configuration
@EnableAsync
public class AsyncMessageConfig implements AsyncConfigurer {

	@Override
	public Executor getAsyncExecutor() {
		// 配置线程池相关参数
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(5); // 最少线程数
		executor.setMaxPoolSize(10); // 最大线程数
		executor.setQueueCapacity(25); // 缓冲队列数
		executor.initialize();
		return executor;
	}

	@Override
	public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
		return null;
	}

}
